"use strict";
const { Model, Sequelize } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class ContractPayment extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      ContractPayment.belongsTo(models.Contract, {
        foreignKey: "contract_id",
      });
      ContractPayment.belongsTo(models.Staff, {
        foreignKey: "manager_id",
        as: "manager",
      });
      // define association here
    }
  }
  ContractPayment.init(
    {
      payment_type: DataTypes.STRING, //是收款还是汇款
      status: DataTypes.STRING, //状态
      remarks: DataTypes.STRING, //备注
      payment_date: {
        type: DataTypes.DATEONLY,
        defaultValue: Sequelize.NOW,
      },
      payment_money: DataTypes.FLOAT,
      approval_status: {
        type: DataTypes.STRING,
        defaultValue: "待审核",
      },
      proportion: DataTypes.STRING,
    },
    {
      sequelize,
      modelName: "ContractPayment",
      tableName: "contractpayments",
    }
  );
  return ContractPayment;
};
